package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class NormalizesTheInputArrayToDoubleValuesBetween {
	public static double[] normalize(short[] input) {
		double[] normalizedSamples = new double[input.length];

		int max = maxValue(input);

		for (int i = 0; i < input.length; i++) {
			normalizedSamples[i] = ((double) input[i]) / max;
		}

		return normalizedSamples;
	}

	public static double[] normalize(double[] input) {
		double[] normalizedSamples = new double[input.length];

		double max = maxValue(input);

		for (int i = 0; i < input.length; i++) {
			normalizedSamples[i] = input[i] / max;
		}

		return normalizedSamples;
	}


	public static short maxValue(short[] input) {
		short max = Short.MIN_VALUE;
		for (int i = 0; i < input.length; i++) {
			if (Math.abs(input[i]) > max) {
				max = (short) Math.abs(input[i]);
			}
		}
		return max;
	}


	public static double maxValue(double[] input) {
		double max = Double.MIN_VALUE;
		for (int i = 0; i < input.length; i++) {
			if (Math.abs(input[i]) > max) {
				max = Math.abs(input[i]);
			}
		}
		return max;
	}
}
